import { Example4TestClass, UnityEngine } from "csharp";

/** 普通的方法 */
export function func1(){
    console.log(`ts:test call func1`);    
}
/** 带有参数的方法 */
export function func2(s:string){
    console.log(`ts:test call func2,s=${s}`);    
}

let gameobject:UnityEngine.GameObject;
/** 传入一个GameObject的方法 */
export function func3(obj:UnityEngine.GameObject){
    console.log(`ts:test call func3,gameobject = ${obj.name}`);
    gameobject = obj;
    setInterval(()=>{
        gameobject.transform.Rotate(300*UnityEngine.Time.deltaTime,0,0);
    })
}
/* 将传入的C#对象中的action重设 */
export function func4(component:any){
    console.log(`ts:test call func4,c=${component}`);
    let a = 1;
    component.action1 = ()=>{
        gameobject.transform.localScale = new UnityEngine.Vector3(a,a,a);
        a += UnityEngine.Time.deltaTime;
        if(a >=3){
            a = 1;
        }
    }
}
/* 从JS中返回数据到C# */
export function func5():string{
    console.log(`ts:test call func5`);
    return "from func5 return data";
}
/* 返回之前传入的GameObject */
export function func6():UnityEngine.GameObject{
    console.log(`ts:test call func6`);
    return gameobject;
}
/** 使用C#自定义类，数据修改，静态方法调用 */
function testCallCSharp(){
    let test = new Example4TestClass();
    console.log(`test class str = ${test.str}`);
    test.str = "change in ts code";
    test.LogStr();
    const s = Example4TestClass.TestCall("call from ts code !!");
    console.log(`test call static func,s=${s}`);    
}
testCallCSharp();